
function isAndroid() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

  if (/android/i.test(userAgent)) {
    return true;
  }
  return false;
}

function fetchHotpointSummary(options = {}) {
  XT.signJsonp({
    url: '/account/hotpoint-summary',
    data: {userId: XT.search.userId},
    super_success: function(res){
      // console.log('/account/account-by-id=====', res);
      options.callback && options.callback(res || []);
    }
  })
}

var store = new Vuex.Store({
  state: {
    showLoading: true,
    hotPointSummary: {}
  },
  actions: {
    getHotpointSummary({commit, state}, payload = {}){
      commit('HIDE_LOADING');
      fetchHotpointSummary({
        callback: function(res) {
          commit('HIDE_LOADING');
          if(res.code == 'ok') {
            commit('HOT_POINT_SUMMARY', {hotPointSummary: res.data})
          }
        }
      })
    },
  },
  mutations: {
    HOT_POINT_SUMMARY(state, payload = {}) {
      state.hotPointSummary = payload.hotPointSummary;
    },
    HIDE_LOADING(state, payload = {}) {
      state.showLoading = false;
    }
  }
});

window.App = new Vue({
  el: '#App',
  store: store,
  data: {

  },
  methods: {
    openWx: function() {
      var that = this;
      XT.bridge.call('copyToClipboard',{content: encodeURIComponent('百媚直播服务号')},function (res) {
        if(isAndroid()) {
          setTimeout(function(){
            that.openWxDialog()
          }, 2000)
        }else {
          that.openWxDialog()
        }
      });

      // var context = new Clipboard("#WxBtn");
      // context.on("success",function(e){
      //  MINT.MessageBox({
      //    title: '提示',
      //    message: '点击微信右上角+号,"添加朋友"粘贴并搜索,即可关注',
      //    showCancelButton: true,
      //    confirmButtonText: '前往微信',
      //    closeOnClickModal: true
      //  }).then(action => {
      //    if(action == 'confirm') {
      //      window.location.href = 'bmlive://bmlive/openWX';
      //    }
      //  })
      // });
      //
      // context.on('error', function() {
      //  MINT.Toast('复制失败');
      // })

    },
    openWxDialog: function() {
      MINT.MessageBox({
        title: '提示',
        message: '点击微信右上角+号,"添加朋友"粘贴并搜索,即可关注',
        showCancelButton: true,
        confirmButtonText: '前往微信',
        closeOnClickModal: true
      }).then(action => {
        if(action == 'confirm') {
          window.location.href = 'bmlive://bmlive/openWX';
        }
      })
    },
    callCustomerService: function() {
      window.location.href = 'bmlive://bmlive/callCustomerService';
    }
  },
  computed: {
    showLoading: function() {
      return this.$store.state.showLoading;
    },
    hotPointSummary: function() {
      return this.$store.state.hotPointSummary;
    }
  },
  created: function() {
    var that = this;
    XT.getUserInfo(function(info){
      that.$store.dispatch('getHotpointSummary');
    });
  },
  mounted: function() {

  }
});

